Post

Replies

Boosts

Views

Activity

Reply to SwiftUI: Force orientation on a per screen basis
Approach described above didn't work for me no matter what I did. Then I discovered swiftui-interface-orientation and it works for me fine. It is even little bit easier to use. I did these steps to make it work: In Xcode only Portrait orientation is selected. App delegate is marked as @main instead of SwiftUI App. InterfaceOrientationCoordinator.shared.allowOverridingDefaultOrientations is set to true in didFinishLaunchingWithOptions method. I have to create window manually in didFinishLaunchingWithOptions and use UIHostingController as root controller: let window = UIWindow() window.rootViewController = UIHostingController(rootView: makeRootView(store: rootStore)) window.makeKeyAndVisible() self.window = window This method is added to App delegate: func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { InterfaceOrientationCoordinator.shared.supportedOrientations } Then I use interfaceOrientations() modifier on any view: MediaBrowserView() .interfaceOrientations([.portrait, .landscape])
Mar ’24